    <!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ss="http://schemas.Kherty.com/office/2007/spreadsheet"
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals" xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" x:Class="OpenLS.Spreadsheet.UI.DefinedNamesResources"
    >
  <DataTemplate DataType="{x:Type ss:DefinedName}">
    <TextBlock Text="{Binding Name}"/>
  </DataTemplate>
  <DataTemplate DataType="{x:Type ss:Worksheet}" x:Key ="definedNames">
        <Grid>
            <Grid.Resources>
                <CollectionViewSource Source="{Binding Path=Workbook.DefinedNames}" x:Key="v">
                    <CollectionViewSource.SortDescriptions>
                        <ComponentModel:SortDescription PropertyName="Name"></ComponentModel:SortDescription>
                    </CollectionViewSource.SortDescriptions>
                </CollectionViewSource>
            </Grid.Resources>

            <ComboBox IsEditable ="True" ItemsSource="{Binding Path=Workbook.DefinedNames, Converter={x:Static Internals:SpreadsheetConverters.DefinedNamesFactory}}"
               Text="{Binding Path=Selection.NameOrLabel, Mode=OneWay}"
               SelectionChanged="OnDefinedNameChanged" BorderBrush ="{x:Null}" HorizontalAlignment="Stretch" PreviewKeyDown="OnKeyDown">
          
                <ComboBox.Style>
          <Style TargetType="{x:Type ComboBox}" >
            <Style.Triggers>
              <Trigger Property="ComboBox.IsEditable" Value="True">
                <Setter Property="KeyboardNavigation.IsTabStop" Value="False">
                </Setter>
                <Setter Property="Control.Padding" Value="0,1,0,1">
                </Setter>
                <Setter Property="Control.Template">
                  <Setter.Value>
                    <ControlTemplate TargetType="ComboBox">
                      <Grid SnapsToDevicePixels="True">
                        <Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Bd"
                                Background="{TemplateBinding Panel.Background}" Padding="1,1,1,1">
                          <Grid Grid.IsSharedSizeScope="True">
                            <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="1" />
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition SharedSizeGroup="ComboBoxButton" Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Border Margin="{TemplateBinding Padding}" Grid.ColumnSpan="2" x:Name="SelectedItemBorder"/>
                            <TextBox Margin="{TemplateBinding Control.Padding}" 
                                     HorizontalContentAlignment="{TemplateBinding Control.HorizontalContentAlignment}" 
                                      VerticalContentAlignment="{TemplateBinding Control.VerticalContentAlignment}" 
                                      Name="PART_EditableTextBox" IsReadOnly="False" Grid.Column="1" Tag="definedName" >
                              <TextBox.Style>
                                <Style TargetType="TextBox">
                                  <Style.Resources>
                                    <ResourceDictionary />
                                  </Style.Resources>
                                  <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True"/>
                                  <Setter Property="UIElement.AllowDrop" Value="False"/>
                                  <Setter Property="TextAlignment" Value="Center"/>
                                  <Setter Property="FrameworkElement.MinWidth" Value="0"/>
                                  <Setter Property="FrameworkElement.MinHeight" Value="0"/>
                                  <Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/>
                                  <Setter Property="Control.Template">
                                    <Setter.Value>
                                      <ControlTemplate TargetType="TextBox">
                                        <ScrollViewer Name="PART_ContentHost" Background="#00FFFFFF" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Focusable="False" />
                                      </ControlTemplate>
                                    </Setter.Value>
                                  </Setter>
                                  <Style.Triggers>
                                    <Trigger Property="IsFocused" Value="True">
                                      <Setter Property ="TextAlignment" Value="Left"/>
                                    </Trigger>
                                  </Style.Triggers>
                                </Style>
                              </TextBox.Style>
                            </TextBox>
                            <ToggleButton Background="{x:Null}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource Mode=TemplatedParent, AncestorType={x:Null}}}" Grid.ColumnSpan="3">
                              <ToggleButton.Style>
                                <Style TargetType="ToggleButton">
                                  <Setter Property="FrameworkElement.MinWidth" Value="0"/>
                                  <Setter Property="FrameworkElement.MinHeight" Value="0"/>
                                  
                                  <Setter Property="Panel.Background" Value="#00FFFFFF"/>
                                  <Setter Property="UIElement.Focusable" Value="False"/>
                                  <Setter Property="ButtonBase.ClickMode" Value="Press"/>
                                  <Setter Property="Control.Template">
                                    <Setter.Value>
                                      <ControlTemplate TargetType="ToggleButton">
                                        <Grid Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
                                          <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition SharedSizeGroup="ComboBoxButton" Width="12" />
                                          </Grid.ColumnDefinitions>
                                          <Rectangle Fill="Transparent" Grid.ColumnSpan="2"/>
                                          <Path Fill="Black" Data="M0,0 L9,0 L 4.5,4.5 Z" Grid.Column="1" SnapsToDevicePixels="True" VerticalAlignment="Center"/>
                                        </Grid>
                                      </ControlTemplate>
                                    </Setter.Value>
                                  </Setter>
                                </Style>
                              </ToggleButton.Style>
                            </ToggleButton>
                          </Grid>
                        </Border>
                        <Popup Placement="Bottom" Name="PART_Popup" Focusable="False" AllowsTransparency="True" 
                                IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource Mode=TemplatedParent, AncestorType={x:Null}}}"
                                PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
                          <Grid>
                            <Border MinWidth="{TemplateBinding FrameworkElement.ActualWidth}" 
                                    MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}" Name="Shdw">
                              <Border BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1,1,1,1" Name="DropDownBorder" 
                                      Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                                <ScrollViewer>
                                  <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                              </Border>
                            </Border>
                          </Grid>
                        </Popup>
                      </Grid>
                      <ControlTemplate.Triggers>
                        <Trigger Property="ItemsControl.HasItems" Value="False">
                          <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder" Value="95">
                          </Setter>
                        </Trigger>
                        <Trigger Property="UIElement.IsEnabled" Value="False">
                          <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}">
                          </Setter>
                          <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                        </Trigger>
                        <Trigger Property="ItemsControl.IsGrouping" Value="False">
                          <Setter Property="ScrollViewer.CanContentScroll" Value="False">
                          </Setter>
                        </Trigger>
                        <Trigger Property="Popup.HasDropShadow" SourceName="PART_Popup" Value="False">
                          <Setter Property="FrameworkElement.Margin" TargetName="Shdw" Value="0,0,5,5"/>
                        </Trigger>
                      </ControlTemplate.Triggers>
                    </ControlTemplate>
                  </Setter.Value>
                </Setter>
              </Trigger>
            </Style.Triggers>
            <Setter Property="FrameworkElement.FocusVisualStyle">
              <Setter.Value>
                <Style TargetType="IFrameworkInputElement">
                  <Style.Resources>
                    <ResourceDictionary />
                  </Style.Resources>
                  <Setter Property="Control.Template">
                    <Setter.Value>
                      <ControlTemplate>
                        <Rectangle Margin="4,4,21,4" SnapsToDevicePixels="True" Stroke="#FF000000" StrokeDashArray="1 2" StrokeThickness="1" />
                      </ControlTemplate>
                    </Setter.Value>
                  </Setter>
                </Style>
              </Setter.Value>
            </Setter>
            <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}">
            </Setter>
            <Setter Property="Panel.Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
            </Setter>
            <Setter Property="Border.BorderBrush" Value="#FF7F9DB9"/>
            <Setter Property="Border.BorderThickness" Value="1,1,1,1"/>
            <Setter Property="Control.Padding" Value="1,1,1,1"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
            <Setter Property="Control.VerticalContentAlignment" Value="Center"/>
            <Setter Property="Control.Template">
              <Setter.Value>
                <ControlTemplate TargetType="ComboBox">
                  <Grid SnapsToDevicePixels="True">
                    <Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Bd" Background="{TemplateBinding Panel.Background}" Padding="1,1,1,1">
                      <Grid Grid.IsSharedSizeScope="True">
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="1" />
                          <ColumnDefinition Width="*" />
                          <ColumnDefinition SharedSizeGroup="ComboBoxButton" Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Border Margin="{TemplateBinding Control.Padding}" Name="SelectedItemBorder" Grid.ColumnSpan="2" />
                        <ContentPresenter Margin="{TemplateBinding Control.Padding}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}" Content="{TemplateBinding ComboBox.SelectionBoxItem}" Grid.Column="1" />
                        <ToggleButton IsChecked="False" Grid.ColumnSpan="3">
                          <ToggleButton.Style>
                            <Style TargetType="ToggleButton">
                              <Style.Resources>
                                <ResourceDictionary />
                              </Style.Resources>
                              <Setter Property="FrameworkElement.MinWidth" Value="0"/>
                              <Setter Property="FrameworkElement.MinHeight" Value="0"/>
                              <Setter Property="Panel.Background" Value="#00FFFFFF"/>
                              <Setter Property="UIElement.Focusable" Value="False"/>
                              <Setter Property="ButtonBase.ClickMode" Value="Press"/>
                              <Setter Property="Control.Template">
                                <Setter.Value>
                                  <ControlTemplate TargetType="ToggleButton">
                                    <Grid Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
                                      <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition SharedSizeGroup="ComboBoxButton" Width="Auto" />
                                      </Grid.ColumnDefinitions>
                                      <Path Fill="Black" Data="M0,0 L9,0 L 4.5,4.5 Z" SnapsToDevicePixels="True" VerticalAlignment="Center"/>
                                    </Grid>
                                  </ControlTemplate>
                                </Setter.Value>
                              </Setter>
                            </Style>
                          </ToggleButton.Style>
                        </ToggleButton>
                      </Grid>
                    </Border>
                    <Popup Placement="Bottom" Name="PART_Popup" Focusable="False" 
                           AllowsTransparency="True" IsOpen="True" 
                      PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
                      <Border MinWidth="{TemplateBinding FrameworkElement.ActualWidth}" 
                              MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}" Name="Shdw"  Height="200">
                        <Border BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1,1,1,1" Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                          <ScrollViewer>
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained" />
                          </ScrollViewer>
                        </Border>
                      </Border>
                    </Popup>
                  </Grid>
                  <ControlTemplate.Triggers>
                    <MultiTrigger>
                      <MultiTrigger.Conditions>
                        <Condition Property="ComboBox.IsSelectionBoxHighlighted" Value="True">
                        </Condition>
                        <Condition Property="ComboBox.IsDropDownOpen" Value="False">
                        </Condition>
                      </MultiTrigger.Conditions>
                      <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                    </MultiTrigger>
                    <Trigger Property="ComboBox.IsSelectionBoxHighlighted" Value="True">
                    </Trigger>
                    <Trigger Property="Popup.HasDropShadow" SourceName="PART_Popup" Value="True">
                      <Setter Property="FrameworkElement.Margin" TargetName="Shdw" Value="0,0,5,5">
                      </Setter>
                    </Trigger>
                    <Trigger Property="ItemsControl.HasItems" Value="False">
                      <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder" Value="95"/>
                    </Trigger>
                    <Trigger Property="UIElement.IsEnabled" Value="False">
                      <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                      <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                    </Trigger>
                    <Trigger Property="ItemsControl.IsGrouping" Value="True">
                      <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
                    </Trigger>
                  </ControlTemplate.Triggers>
                </ControlTemplate>
              </Setter.Value>
            </Setter>
          </Style>
        </ComboBox.Style> 
        
      </ComboBox>
        </Grid>
    </DataTemplate>

</ResourceDictionary>